package cn.itcast.nems.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.Objects;

/**
 * 分页查询实体
 * @author zhouwei
 * @date 8/30/23 2:51 PM
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class PageQueryModel<T extends QueryParam> implements Serializable {
    private static final long serialVersionUID = -8342897476407175943L;
    
    private Integer pageNumber;
    private Integer pageSize;
    private T condition;
    
    public final void convert() {
        this.setPageNumber(Objects.nonNull(this.getPageNumber()) ? this.getPageNumber() : 1);
        this.setPageSize(Objects.nonNull(this.getPageSize()) ? this.getPageSize() : 30);
    }
    public final void convert(Integer defaultSize) {
        this.setPageNumber(Objects.nonNull(this.getPageNumber()) ? this.getPageNumber() : 1);
        this.setPageSize(Objects.nonNull(this.getPageSize()) ? this.getPageSize() : defaultSize);
    }
}